package org.real.guetshop.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.real.guetshop.annotation.AutoFill;
import org.real.guetshop.enumeration.OperationType;
import org.real.guetshop.pojo.dto.EmployeeDTO;
import org.real.guetshop.pojo.dto.EmployeePageQueryDTO;
import org.real.guetshop.pojo.entity.Employee;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 新增员工
     * @param employee
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into employee (username, password, name, create_user, create_time, update_user, update_time) " +
            "values (#{username}, #{password}, #{name}, #{createUser}, #{createTime}, #{updateUser}, #{updateTime})")
    void insertNewEmployee(Employee employee);

    /**
     * 员工分页查询
     * @param employeePageQueryDTO
     * @return
     */
    Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 删除员工
     * @param employeeDTO
     */
    @Delete("delete from employee where username = #{username} and name = #{name}")
    void deleteEmployee(EmployeeDTO employeeDTO);

    /**
     * 修改员工信息
     * @param employee
     */
    @AutoFill(OperationType.UPDATE)
    void updateEmployee(Employee employee);

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @Select("select * from employee where id = #{id}")
    Employee getById(Integer id);
}
